<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加机构信息</title>
<link rel="stylesheet" type="text/css" href="css/css.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>

<style>
	
	#emptable td{
		font-size: 16px;
		border:none !important;
	}
	.bbD .td{
		font-size: 16px;
		text-aign:right;
	}
	.text2{
		font-size: 16px;
		text-aign:right;
		width: 300px;
	}
    .button{
			margin-top:20px;
			font-size: 16px;
			width: 135px;
			height: 40px;
			border-radius:20px;
			border: 1px solid #ccc;
			margin-left: 35px;
			color: #fff;
			background-color: #47a4e1
	}
   
</style>
<script type="text/javascript">
	
	/* 姓名验证 */
	function checkName(){
		$("#nameinfo").html("");
		var contactname=$("#contactname").val();
		var reg = /^[\u4E00-\u9FA5A-Za-z]+$/;
		if(contactname==null || ""==contactname){
			$("#nameinfo").html("联系人姓名不能为空").css({color:"red"});
			return false;
		}else if(!reg.test(contactname)){
			$("#nameinfo").html("只能输入中文和英文").css({color:"red"});
		}
		return true;
	}
	
	/* 职务验证 */
	function checkDuty(){
		$("#dutyinfo").html("");
		var duty=$("#duty").val();
		var reg = /^[\u4E00-\u9FA5A-Za-z]+$/;
		if(duty==null || ""==duty){
			$("#dutyinfo").html("职务不能为空").css({color:"red"});
			return false;
		}else if(!reg.test(duty)){
			$("#dutyinfo").html("只能输入中文和英文").css({color:"red"});
		}
		return true;
	}
	
	/* 手机号码验证 */
	function checkPhone(){
			$("#phoneinfo").html("");
			var phone=$("#phone").val();
			var reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
			if(phone==null || ""==phone){
				$("#phoneinfo").html("手机号不能为空!").css({color:"red"});
				return false;
			}else if(!reg.test(phone)){
				$("#phoneinfo").html("手机号码格式不正确").css({color:"red"});
				return false;
			}else if(phone.length!=11){
				$("#phoneinfo").html("手机必须是11位数字").css({color:"red"});
				return false;
			}else{
				$.ajax({
				url:"phonevalidate.do",
				type:"POST",
				dataType:"json",
				data:"phone="+phone,
				success:function(result){
					if(result.res=="true"){
						$("#phoneinfo").html("此联系人已存在！").css({color:"red"});
						return false;
					}
					if(result.res=="false"){
						return true;
					}
				}
			}); 
		}
		return true;
	}
	/* 工作电话验证 */
	function checkTel(){
		$("#telinfo").html("");
		var reg=/^((0\d{2,3})-)(\d{7,8})+$/;
		var tel=$("#tel").val();
		if(tel==null || ""==tel){
			$("#telinfo").html("电话不可以为空").css({color:"red"});
			return false;
		}else if(!reg.test(tel)){
			$("#telinfo").html("电话格式必须是'0xx/0xxx-xxxxxxx'").css({color:"red"});
			return false;
		}
		return true;
	}
	
	/* 邮箱验证 */
	function checkEmail(){
		$("#emailinfo").html("");
		var email=$("#email").val();
		var reg= /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		if(email==null || ""==email){
			$("#emailinfo").html("邮箱不能为空").css({color:"red"});
			return false;
		}else if(!reg.test(email)){
			$("#emailinfo").html("邮箱格式不对").css({color:"red"});
			return false;
		}
		return true;
	}
	/* QQ验证 */
	function checkQQ(){
		$("#qqinfo").html("");
		var reg = /^\d+$/;
		var qq=$("#qq").val();
		if(qq==null || ""==qq){
			$("#qqinfo").html("qq不可以为空").css({color:"red"});
			return false;
		}else if(!reg.test(qq)){
			$("#qqinfo").html("qq必须是数字").css({color:"red"});
			return false;
		}else if(qq.length<5 || qq.length>11){
			$("#qqinfo").html("qq必须是5-11位数字").css({color:"red"});
			return false;
		}
		return true;
	}
	
	
	/* 经办人手机号码验证 */
 	function checkEphone(){
		$("#ephoneinfo").html("");
		var ephone=$("#ephone").val();
		var reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
		if(ephone==null || ""==ephone){
			$("#ephoneinfo").html("手机号不能为空").css({color:"red"});
			return false;
		}
		return true;
	} 
	
	function checkEphoneByName(){
		var ename=$("#ename").val();
		$.ajax({
			url:"checkEphoneByName.do",
			type:"POST",
			data:"ename="+ename,
			dataType:"json",
			success:function(result){
				$("#ephone").val(result.ephone);
			}
			
		})
	}
	
	
	function isExsit(){
		if(checkName() && checkDuty() && checkPhone() && checkTel() && checkEmail() && checkQQ() && checkEphone()){
			return true;
		}else{
			return false;
		}
	}
	

	
</script>

</head>
<body>
	<div id="pageAll">
		<div class="pageTop">
			<div class="page">
				<img src="img/coin02.png" /><span><a href="main.html">首页</a>&nbsp;-&nbsp;
				<a href="infomanage.do">机构管理</a>&nbsp;-<a href="contact.do">联系人管理</a>&nbsp;-&nbsp;添加联系人</span>
			</div>
		</div>
		<div class="page ">
			<!-- 上传广告页面样式 -->
			<div class="banneradd bor">
				<form action="contactmanageadd.do" method="post" onsubmit="return isExsit()">
				<div class="baTopNo">
					<span>添加联系人信息</span>
					<hr/>
				</div>
				<div class="baBody" >
					<table id="emptable">
						<tr class="bbD">
							<td class="td">联系人姓名：</td><td><input type="text" class="input3" name="name" id="contactname" onblur="checkName()" /></td>
							<td><span id="nameinfo"></span></td>
						</tr>
						<tr class="bbD" >
							<td class="td">性别：</td>
							<td>
								<input type="radio"  name="sex" value="1" checked="checked"/>男&nbsp;&nbsp;&nbsp;
								<input type="radio"  name="sex" value="0"/>女
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">职务：</td><td><input type="text" class="input3" name="duty" id="duty" onblur="checkDuty()"/></td>
							<td><span id="dutyinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">手机号码：</td><td><input type="text" class="input3" name="phone" id="phone" onblur="checkPhone()"/></td>
							<td><span id="phoneinfo"></span></td>	
						</tr>
					
						<tr class="bbD">
							<td class="td">工作电话：</td><td><input type="text" class="input3" name="tel" id="tel" onblur="checkTel()"/></td>
							<td><span id="telinfo"></span></td>
						</tr>
					
						<tr class="bbD">
							<td class="td">邮箱：</td><td><input class="input3" type="text" name="email" id="email" onblur="checkEmail()"/></td>
							<td><span id="emailinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">QQ：</td><td><input class="input3"type="text" name="qq" id="qq" onblur="checkQQ()"/></td>
							<td><span id="qqinfo" ></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">微信：</td><td><input class="input3"type="text" name="weixin" /></td>
						</tr>
						<tr class="bbD">
							<td class="td">重要等级：</td>
							<td>
								<select class="input3" name="vip">
									<option value="1">一般</option>
									<option value="2">重要</option>
									<option value="3">非常重要</option>
								</select>
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">跟进状态：</td>
							<td>
								<select class="input3" name="follow">
									<option value="1">有效</option>
									<option value="2">无效</option>
									<option value="3">未处理</option>
								</select>
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">经办人姓名：</td>
							<td>
								<select class="input3" name="ename" id="ename" onchange="checkEphoneByName()" >
									<c:forEach items="${sessionScope.emps }" var="emp">
										<option value="${emp.empname }">${emp.empname }</option>
									</c:forEach>
								</select>
							</td>
							<td><span id="enameinfo"></span></td>
						</tr>
						<tr class="bbD">
							<td class="td">经办人手机号：</td><td><input class="input3"type="text" name="ephone" id="ephone" onblur="checkEphone()" readonly="readonly"/></td>
							<td><span id="ephoneinfo"></span></td>
						</tr>
						<tr class="bbD" >
							<td class="td">是否认可：</td>
							<td>
								<input type="radio"  name="accept" value="1" checked="checked"/>认可&nbsp;&nbsp;&nbsp;
								<input type="radio"  name="accept" value="0"/>不认可
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">认可理由：</td>
							<td class="input3">
								<textarea class="text2" name="reason"></textarea>
							</td>
						</tr>
						<tr class="bbD">
							<td class="td">信息来源：</td><td><input class="input3"type="text" name="info" /></td>
						</tr>
						<tr class="bbD">
							<td class="td">备注：</td>
							<td class="input3">
								<textarea class="text2" name="remark"></textarea>
							</td>
						</tr>
					</table>	
						<input class="button" type="submit" value="添加" id="input3" />
						<input class="button" type="reset" value="重置" id="input3" />
				</div>
				</form>
			</div>
			<!-- 上传广告页面样式end -->
		</div>
	</div>
</body>
</html>